import request from "@/utils/request";
import { defineStore } from "pinia";
import { BannerItem,GoodsNew,GoodsHot } from '@/types/goods'
import { IResponse } from '@/types/data'

export default defineStore('home', {
  state() {
    return {
      list: [] as BannerItem[],
      newGoodsList:[] as GoodsNew[],
      hotGoodsList:[] as GoodsHot[]
    }
  },
  actions: {
    // 轮播图
    async getBannerList() {
      const r = await request.get<IResponse<BannerItem[]>>('/home/banner')
      console.log(r);
      this.list=r.data.result
    },
    // 新鲜好物
    async getNewGoodsList(){
      const r=await request.get<IResponse<GoodsNew[]>>('/home/new')
      console.log(r);
      this.newGoodsList=r.data.result
    },
    // 人气推荐
    async getHotGoodsList(){
      const r=await request.get<IResponse<GoodsHot[]>>('/home/hot')
      console.log(r);
      this.hotGoodsList=r.data.result
    }
  }
})